home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17240 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Problem with the ifstream class !!!
  5. Date: Sun, 14 Apr 1996 03:07:50 GMT
  6. Organization: Netcom
  7. Message-ID: <31706b14.276036299@nntp.ix.netcom.com>
  8. References: <4kc2si$8pp@web.cae.ca>
  9. NNTP-Posting-Host: ix-dc7-26.ix.netcom.com
  10. X-NETCOM-Date: Sat Apr 13  8:06:54 PM PDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. Salim Mansouri <salim> wrote:
  14.  
  15. > Hi,
  16. > I am using the ifstream class for reading an ASCII file. 
  17. > ex:    char szTmp[255] = "";
  18. >     ifstream fin("file.txt");
  19. >     while (fin)
  20. >     {
  21. >         fin.getline(szTmp, 250);
  22. >         cout<<"The line is : "<<szTmp<<endl;        
  23. >     }
  24. >     The problem is that it reads twice the last line ????
  25. > Am i missing something. 
  26. > N.B: I am compiling on SGI IRIX 5.3 .
  27.  
  28. It's not reading the last line twice -- it's failing after reading the
  29. last line but you're ignoring that.
  30.  
  31.     while (fin)
  32.  
  33. returns loops until fin has failed, not until it's about to fail.  You
  34. want something like
  35.  
  36.     while (fin.getline(szTmp, 250))
  37.       cout << "The line is : " << szTmp << endl;
  38.  
  39.  
  40. Michael M Rubenstein
  41.